package com.mgr.controller;

import java.util.ArrayList;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.mgr.model.Accounts;
import com.mgr.model.Customers;
import com.mgr.service.AccountService;
import com.mgr.util.EncryptionNumeric;

@Controller
@RequestMapping("downloadPDF")
public class PrintPdfController {
	
	@Autowired
	AccountService accService;
	
	@RequestMapping("balance")
	public ModelAndView downloadPdfBalance(Map<String, Object> map, HttpServletRequest request) {
		
		// Declare variable
		EncryptionNumeric coder = new EncryptionNumeric();
		String accId = coder.decoding(request.getParameter("acc"));	
		ArrayList<String[]> accountInfo = new ArrayList<String[]>();
		Customers cust = accService.getCustomerByAccId(Integer.parseInt(accId));
		Accounts account = accService.getAccount(Integer.parseInt(accId));
		String[] temp = new String[2];
		
		// Title print
		temp[0] = "TITLE";
		temp[1] = "VIEW BALANCE";
		accountInfo.add(temp);
		
		// Data print (two column)
		temp = new String[2];
		temp[0] = "CUSTOMER NAME";	// Colum 1
		temp[1] = cust.getCustName().toUpperCase();	// Colum 2
		accountInfo.add(temp);
		temp = new String[2];
		temp[0] = "ACCOUNT NUMBER";
		temp[1] = "" + account.getAccId();
		accountInfo.add(temp);
		temp = new String[2];
		temp[0] = "BALANCE";
		temp[1] = account.getBalance() + " VND";
		accountInfo.add(temp);
		temp = new String[2];
		temp[0] = "TYPE";
		temp[1] = account.getAccType();
		accountInfo.add(temp);
		temp = new String[2];
		temp[0] = "ACCOUNT STATUS";
		temp[1] = account.isAccStatus()?"Enable":"Disable";
		accountInfo.add(temp);
		
		return new ModelAndView("pdfView", "printData", accountInfo);
	}
}
